package org.familysearch.fsapi.gwt.server.dao.rest.parsers;

import org.familysearch.fsapi.gwt.common.Logger;
import org.familysearch.fsapi.gwt.common.client.entities.Date;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class DateSAXParser extends DefaultHandler {

	private String tempVal = "";
	private Date date = new Date();
	private Logger log;
	
	public DateSAXParser()
	{	
		log = Logger.getLogger(this.getClass().getName());
	}
	
	public void startElement(
			String uri, 
			String localName, 
			String qName,
			Attributes attributes) throws SAXException {

			log.debug("startElement="+qName);
			

	}

	public void characters(char[] ch, int start, int length) throws SAXException {
		tempVal = new String(ch,start,length);
		log.debug("tempVal="+tempVal);
	}

	public void endElement(String uri, String localName,
			String qName) throws SAXException {

			log.debug("endElement="+qName);
						
			// original date
			if(qName.equalsIgnoreCase("original")) {
				date.setOriginal(tempVal);
			}
			
			// normalized date
			if(qName.equalsIgnoreCase("normalized")) {
				date.setOriginal(tempVal);
			}
			
			//TODO: parse the rest of Date here as necessary
	}
	

}
